﻿
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using Model;
using MsDAL;
using System.ComponentModel;
using Components;

namespace ServiceHelper
{
    [DataObjectAttribute]
    public partial class Bas1a13Manager : Bas1a13Base
    {
        private Bas1a13DAL bas1a13Dal = new Bas1a13DAL();

        private static Bas1a13Manager _entity;

        public static Bas1a13Manager Entity
        {
            get
            {
                if (_entity == null)
                    _entity = new Bas1a13Manager();
                return _entity;
            }
        }

        #region 个人代码
        public string SaveData(Hashtable tb, DataTable dtl, DataTable deldata, string action, string usercode)
        {
            List<SqlApp> lst = new List<SqlApp>();

            Bas1a13 model = null;
            if (dtl == null || dtl.Rows.Count == 0 && "A" == action) return "明细中没有数据，不需要保存！";

            string appstr = Context.GetAppByUserCode(usercode);
            string sellerid = Validation.ToString(tb["slistid"]);
            string pid;
            string spno;
            if (null != dtl)
            {
                foreach (DataRow dr in dtl.Rows)
                {
                    pid = Validation.ToString(dr["pid"]);
                    spno = Validation.ToString(dr["spno"]);

                    if (Validation.IsNull(dr["listid"]))
                    {
                        model = new Bas1a13();
                        model.Pid = pid;
                        model.Spno = spno;
                        model.Muser = appstr;
                        model.Slistid = sellerid;
                        model.Status = 1;
                        model.Listid = Sys0a60Manager.Entity.CreateSn("bas1a13_listid", usercode);//默认为1

                        lst.Add(this.Add(model));
                    }
                    else
                    {
                        lst.Add(bas1a13Dal.UpdateDtl(pid, spno, Validation.ToString(dr["listid"])));
                    }
                }
            }

            if ("M" == action && null != deldata)
            {
                foreach (DataRow dr in deldata.Rows)
                {
                    model = new Bas1a13();
                    model.Listid = Validation.ToString(dr["listid"]);
                    lst.Add(this.Delete(model));
                }
            }

            return CommonManager.Entity.SaveData(lst);
        }

        #endregion
    }
}



